const request = require("../../utils/request.js")
const image = 'https://tdesign.gtimg.com/mobile/demos/example2.png';
const items = new Array(12).fill({ label: '标题文字', image }, 0, 12);

Page({
  offsetTopList: [],
  data: {
    sideBarIndex: 1,
    scrollTop: 0,
    categories1: '',
    list1:'',
    categories: [
      {
        label: '选项一',
        title: '标题一',
        badgeProps: {},
        items,
      },
      {
        label: '选项二',
        title: '标题二',
        badgeProps: {},
        items,
      },
      {
        label: '选项三',
        title: '标题三',
        badgeProps: {},
        badgeProps: {},
        items,
      },
      {
        label: '选项四',
        title: '标题四',
        badgeProps: {},
        items,
      },
      {
        label: '选项五',
        title: '标题五',
        badgeProps: {},
        items,
      },
    ],
    navbarHeight: 0,
    list:[
      {id:1,image:"/starc/img/coffee1.png",title:"咖啡机咖啡机1",text:"产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介",text2:"265",price:"200",price1:"500"},
      {id:2,image:"/starc/img/coffee2.png",title:"咖啡机咖啡机1",text:"产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介",text2:"265",price:"200",price1:"500"},
      {id:3,image:"/starc/img/coffee3.png",title:"咖啡机咖啡机1",text:"产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介",text2:"265",price:"200",price1:"500"},
      {id:4,image:"/starc/img/coffee4.png",title:"咖啡机咖啡机1",text:"产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介",text2:"265",price:"200",price1:"500"},
      {id:5,image:"/starc/img/coffee1.png",title:"咖啡机咖啡机1",text:"产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介",text2:"265",price:"200",price1:"500"},
      {id:6,image:"/starc/img/coffee2.png",title:"咖啡机咖啡机1",text:"产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介",text2:"265",price:"200",price1:"500"},
      {id:7,image:"/starc/img/coffee3.png",title:"咖啡机咖啡机1",text:"产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介",text2:"265",price:"200",price1:"500"},
      {id:8,image:"/starc/img/coffee4.png",title:"咖啡机咖啡机1",text:"产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介:产品简介简介产品简介",text2:"265",price:"200",price1:"500"},
    ]
  },
  
  onLoad() {
    this.getCustomNavbarHeight();
    // 分类菜单列表
    this.getCategories();
    // 分类产品列表
    this.getList();
  },

  // 分类菜单列表
  getCategories(){
    const _this = this
    request.wxRequest('menu/list2', function (err, data) {
      // console.log(data.data.list)
      if (err) {
        // 失败；
      } else {
        _this.setData({
          categories1: data.data.list
        })
      }
    }, 'GET', {
      
    })
  },
  // 分类产品列表
  getList(){
    const _this = this
    request.wxRequest('product/list2', function (err, data) {
      // console.log(data.data.list)
      if (err) {
        // 失败；
      } else {
        _this.setData({
          list1: data.data.list
        })
      }
    }, 'POST', {
      menuId: 1,
      name: 123
    })
  },
  jump:function(e){
    let det = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/shopList/shopList?det='+det,
      success: ()=>{
        console.log('成功');
      }
    })
    },
  getCustomNavbarHeight() {
    const query = wx.createSelectorQuery();
    query.select('.custom-navbar').boundingClientRect();
    query.exec((res) => {
      const { height = 0 } = res[0] || {};
      this.setData({ navbarHeight: height });
    });
  },

  onSideBarChange(e) {
    const { value } = e.detail;

    this.setData({ sideBarIndex: value, scrollTop: 0 });
  },
});
